// --------------------- 8. R-T Scatter Plot ----------------------- //
inline void a(vector<TH1 *> &v, TH1 *h){ v.push_back((TH1 *)h); }

void tt(){
  TFile *f = new TFile(getenv("TMP1"));
  TTree *etf = (TTree *)f->Get("etf");
  vector<TH1 *> v;
  TH1 *h0;
  char zcut[64] = "";
  static const int Z = 29;
  if(Z > 0) sprintf(zcut, "az0>%.2f && az0<%.2f", Z-0.5, Z+0.5);

  const char ud[2] = {'U', 'D'}, xy[2] = {'X', 'Y'}, *trkr[] = {"pre", "post"};
  char hname[64]{}, ly[64]{};
  for(int i = 0; i < 2; i++){ // loop over U, D
    for(int j = 0; j < 2; j++){ // loop over 1, 2
      for(int k = 0; k < 2; k++){ // loop over X, Y
        sprintf(ly, "dcTa%c%d%c", ud[i], j, xy[k]);
        sprintf(hname, "h%s", ly);
        if(0 == i) h0 = new TH2F(hname, Form("t1-t2 of %s", ly), 500, -50., 250., 500, -50., 250.);
        else h0 = new TH2F(hname, Form("t1-t2 of %s", ly), 500, -100., 400., 500, -100., 400.);
        h0->GetXaxis()->SetTitle("drift time of X0 [ns]");
        h0->GetYaxis()->SetTitle("drift time of X1 [ns]");
        // 2: normal trking; 3: global trking
        string cut = Form("%s&&fabs(%sTaTracker%c.ang())<1.&&%s0.fired()>=2&&%s1.fired()>=2", zcut, trkr[i], xy[k], ly, ly);
        etf->Project(hname, Form("%s1.GetT():%s0.GetT()", ly, ly), cut.data());
        a(v, h0);
        cout << "Processing " << ly << ": " << zcut << "...\r" << flush;
      } // end for over X, Y
    } // end for over 1, 2
  } // end for over U, D
  cout << endl;
  TCanvas *c = new TCanvas("c", "T1 v.s. T2 of dcTas", 1680, 1050);
  c->Divide(4, 2);
  for(int i = 0; i < 8; i++){
    c->cd(i+1);
    v[i]->Draw("colz");
  } // end for over i
  c->Print("tt.pdf");
} // end main function
